﻿using AutoMapper;
using MediatR;
using MyMES.Domain.W.Liststructure;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.W.realize;

namespace MyMES.Writer.API.Application.CommendHandlers.W.realize
{
    public class DelArrivalmanagementCommandHanders : IRequestHandler<DelArrivalmanagementCommands, APIResult<Arrivalmanagement>>
    {
        private readonly IBaseRepository<Arrivalmanagement> baseRepository;
        private readonly IMapper mapper;

        public DelArrivalmanagementCommandHanders(IBaseRepository<Arrivalmanagement> baseRepository, IMapper mapper)
        {
            this.baseRepository = baseRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 删除到票信息
        /// </summary>
        /// <param name="request">逻辑删除</param>
        /// <param name="cancellationToken">2025年4月16日11:26:18</param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<Arrivalmanagement>> Handle(DelArrivalmanagementCommands request, CancellationToken cancellationToken)
        {
            APIResult<Arrivalmanagement> result = new APIResult<Arrivalmanagement>();
            result.Code = APIEnum.删除成功;
            result.Msg = "删除成功";
            var map = mapper.Map<Arrivalmanagement>(request);
            var sql = $"Update Arrivalmanagement set IsDelete=true where Aid='{request.Aid}'";
            await baseRepository.Update(map, sql);
            return result;
        }
    }
}
